<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }}</div>
    <div class="table-operator">
      <!-- 搜索板块 -->
      <a-row class="row-item-search">
        <a-form :form="searchForm" class="search-form" layout="inline" @submit="handleSearch">
          <a-form-item label="用户编号">
            <a-input v-decorator="['uid']" placeholder="请输入用户编号"/>
          </a-form-item>
          <a-form-item class="search-btn">
            <a-button html-type="submit" icon="search" type="primary">搜索</a-button>
          </a-form-item>
          <a-form-item class="search-btn">
            <a-button @click="handleReset">重置</a-button>
          </a-form-item>
        </a-form>
      </a-row>
    </div>
    <s-table
        ref="table"
        :data="loadData"
        :loading="isLoading"
        :pageSize="15"
        :scroll="{ x: 1400, y: '420px', scrollToFirstRowOnChange: true }"
        rowKey="id"
    >
      <a-table-column key="uid" align="center" data-index="uid" title="用户编号"/>
      <a-table-column key="balance" align="center" data-index="balance" title="余额">
        <template #default="text">
          <span>{{ text | price }}</span>
        </template>
      </a-table-column>
      <a-table-column key="totalExpense" align="center" data-index="totalExpense" title="累计支出">
        <template #default="text">
          <span>{{ text | price }}</span>
        </template>
      </a-table-column>
      <a-table-column key="totalRecharge" align="center" data-index="totalRecharge" title="累计充值">
        <template #default="text">
          <span>{{ text | price }}</span>
        </template>
      </a-table-column>
      <a-table-column key="freezePrice" align="center" data-index="freezePrice" title="冻结金额">
        <template #default="text">
          <span>{{ text | price }}</span>
        </template>
      </a-table-column>
      <a-table-column key="action" fixed="right" title="操作">
        <template #default="record">
        <span>
          <a @click="handleDetail(record)">详情</a>
        </span>
        </template>
      </a-table-column>
    </s-table>
    <!-- 弹窗 -->
    <WalletForm ref="WalletForm"/>
  </a-card>
</template>

<script>
import * as Api from '@/api/pay/wallet'
import {STable} from '@/components/Table'
import WalletForm from './WalletForm';


export default {
  name: 'Index',
  components: {
    STable,
    WalletForm
  },
  data() {
    return {
      // 当前表单元素
      searchForm: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 正在加载
      isLoading: false,
      // 加载数据方法 必须为 Promise 对象
      loadData: param => {
        return Api.page({...param, ...this.queryParam})
            .then(response => response)
      }
    }
  },
  methods: {
    // 详情
    handleDetail(record) {
      this.$refs.WalletForm.open(record.id)
    },

    /**
     * 刷新列表
     * @param {Boolean} bool 强制刷新到第一页
     */
    handleRefresh(bool = false) {
      this.$refs.table.refresh(bool)
    },

    // 确认搜索
    handleSearch(e) {
      e.preventDefault()
      this.searchForm.validateFields((error, values) => {
        if (!error) {
          this.queryParam = {...this.queryParam, ...values}
          this.handleRefresh(true)
        }
      })
    },

    // 重置搜索表单
    handleReset() {
      this.searchForm.resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.ant-card-body {
  padding: 22px 29px 25px;
}

.order-font {
  padding: 2px 0;
  font-size: 12px;
}
</style>
